<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ch="http://java.sun.com/jsf/composite/channel"
      xmlns:pa="http://java.sun.com/jsf/composite/paymentMethod"
      >
    <!--Author : Dr. M H B Ariyaratne, MO(Health Information), buddhika.ari@gmail.com-->
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>#{labels.topic}</title>
        <!--<h:outputStylesheet library="css" name="style.css" />-->
    </h:head>
    <h:body  >

        <h:form>
            <h:panelGrid columns="4" id="gridSelections" styleClass="alignTop">     

                <p:panel header="Specialities" styleClass="alignTop">       
                    <h:panelGrid columns="1">
                        <p:selectOneListbox converter="specilityCon" id="acSpeciality" value="#{bookingController.speciality}" style="height: 300px; width: 300px; padding: 2px; margin: auto;" >
                            <f:selectItems value="#{doctorSpecialityController.items}" var="s" itemLabel="#{s.name}" itemValue="#{s}" />
                            <p:ajax  event="change" process="@this" update="scStaff" /> 
                            <p:ajax  event="click" process="@this" update="scStaff" /> 
                        </p:selectOneListbox>
                    </h:panelGrid>
                </p:panel>

                <p:panel header="Consultants" id="scStaff" styleClass="alignTop">    
                    <h:panelGrid columns="1">
                        <p:selectOneListbox  converter="stfcon" value="#{bookingController.staff}" style="height: 300px; width: 300px; padding: 2px; margin: auto;" >
                            <f:selectItems value="#{bookingController.consultants}" var="mys" itemLabel="#{mys.person.nameWithTitle}" itemValue="#{mys}" />
                            <!--<f:ajax  event="change" execute="@this" render="tblSessionsOfSelectedConsultant"  />--> 
                            <p:ajax  event="click" process="@this" update="tblSessionsOfSelectedConsultant"  /> 
                        </p:selectOneListbox>
                    </h:panelGrid>
                </p:panel>

                <p:panel header="Sessions" style="min-height: 300px;  padding: 2px; margin: auto;position:relative ;"  styleClass="alignTop">
                    <p:dataTable value="#{bookingController.serviceSessions}" rowKey="#{ses.roomNo}"
                                 id="tblSessionsOfSelectedConsultant" var="ses"
                                 selectionMode="single" 
                                 selection="#{bookingController.selectedServiceSession}" >

                        <p:ajax event="rowSelect" process="@this tblSessionsOfSelectedConsultant" 
                                update=":#{p:component('tblBookingsOfSelectedSession')} :#{p:component('lblSessionTotal')}"
                                listener="#{bookingController.fillBillSessions}" />  


                        <p:column headerText="Session">
                            #{ses.name}
                        </p:column>
                        <p:column headerText="Date">
                            <p:outputLabel value="#{ses.sessionAt}">
                                <f:convertDateTime pattern="dd/MM/yy"/>
                            </p:outputLabel>
                        </p:column>
                        <p:column headerText="Time">
                            <p:outputLabel value="#{ses.startingTime}">
                                <f:convertDateTime pattern="hh:mm a"/>
                            </p:outputLabel>
                        </p:column>
                        <p:column headerText="Fee">
                            <p:outputLabel value="#{ses.originatingSession.totalFee}">
                                <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                            </p:outputLabel>                                                            
                        </p:column>   
                        <p:column rendered="false">
                            <p:commandLink value="Edit" onclick="PF('dlgSessionEdit').show();" />
                        </p:column>

                    </p:dataTable>
                </p:panel>

                <p:panel header="Bookings" rendered="false">
                    <p:dataTable id="tblBookingsOfSelectedSession"
                                 value="#{bookingController.billSessions}" var='bs'
                                 selectionMode="single" rowKey="#{bs.id}"
                                 selection="#{bookingController.selectedBillSession}">
                        <p:ajax event="rowSelect" process="@this" update=":#{p:component('detail')}" 
                                listener="#{channelBillController.createBillfees}" />  

                        <p:column headerText="No">#{bs.serialNo}</p:column>
                        <p:column headerText="Patient Name">#{bs.bill.patient.person.nameWithTitle}</p:column>
                        <p:column headerText="Paid or Not">
                            <p:outputLabel rendered="#{bs.bill.paidAmount eq 0}" value="Credit" style="color: red;"/>
                            <p:outputLabel rendered="#{bs.bill.paidAmount ne 0}" value="Paid"/>
                        </p:column>
                        <p:column headerText="C/R">
                            <p:outputLabel value="Cancelled" rendered="#{bs.bill.cancelled==true}"/>
                            <p:outputLabel value="Refunded" rendered="#{bs.bill.refunded==true}"/>
                        </p:column>   
                        <p:column headerText="Agent">
                            <p:outputLabel value="#{bs.bill.fromInstitution.institutionCode}"/>                          
                        </p:column> 
                        <p:column headerText="P/A">                           
                            <p:outputLabel value="Absent"  rendered="#{bs.absent}"/>  
                        </p:column> 
                    </p:dataTable>                    
                </p:panel>                
            </h:panelGrid>


            <h:panelGrid id="gdManageBookings" columns="2" styleClass="alignTop">

                <p:panel id="gpThisBookingDetails" style="min-width: 500px; max-width: 500px; min-height:400px;max-height: 400px;"  >
                    <f:facet name="header">
                        <h:panelGrid columns="2"  > 
                            <p:outputLabel value="Amount"/>

                            <h:panelGroup id="lblSessionTotal">
                                <p:outputLabel  
                                    value="#{bookingController.selectedServiceSession.originatingSession.totalFfee}"
                                    rendered="#{channelBillController.foriegn}">
                                    <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                </p:outputLabel>
                                <p:outputLabel  
                                    value="#{bookingController.selectedServiceSession.originatingSession.totalFee}"
                                    rendered="#{!channelBillController.foriegn}"
                                    >
                                    <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                </p:outputLabel>

                            </h:panelGroup>

                            
                            <p:selectOneMenu  id="cmbPs" value="#{channelBillController.paymentMethod}" style="display: none;">  
                                <f:selectItems value="OnCall"/>                                                               
                            </p:selectOneMenu>

                            
                        </h:panelGrid>                        

                    </f:facet>
                    <p:tabView>
                        <p:ajax event="tabChange"  process="@this" listener="#{channelBillController.onTabChange}" />
                        <p:tab id="tabNewPt" title="New Pateint">
                            <h:panelGrid columns="2">
                                <h:outputLabel value="Title"/>
                                <p:selectOneMenu  value="#{channelBillController.newPatient.person.title}"  >
                                    <f:selectItems value="#{billController.title}"/>
                                </p:selectOneMenu>
                                <h:outputLabel value="Name"/>
                                <p:inputText autocomplete="off"  id="txtNewPtName" value="#{channelBillController.newPatient.person.name}" style="width: 200px;text-transform:capitalize;">
                                </p:inputText>
                                <h:outputLabel value="Phone"/>
                                <p:inputMask mask="999-9999999" id="txtNewPtPhone" autocomplete="off" maxlength="11" value="#{channelBillController.newPatient.person.phone}">
                                </p:inputMask>
                                <h:outputLabel value="Sex"/>
                                <p:selectOneMenu id="txtNewSex"  value="#{channelBillController.newPatient.person.sex}" style="width: 200px;">
                                    <f:selectItem itemLabel="Select Sex"/>
                                    <f:selectItems value="#{billController.sex}"/>
                                </p:selectOneMenu> 
                                <p:outputLabel value="Area"></p:outputLabel>
                                <p:autoComplete widgetVar="np" id="acnp" forceSelection="true" 
                                                value="#{channelBillController.area}" 
                                                completeMethod="#{areaController.completeArea}" 
                                                var="npt" itemLabel="#{npt.name}" 
                                                itemValue="#{npt}" size="30"  style="width: 40px;">
                                </p:autoComplete>  
                            </h:panelGrid>
                        </p:tab>
                        <p:tab  id="tabSearchPt" title="Search Pateint" rendered="false">
                            <p:autoComplete widgetVar="aPt" id="acPt" forceSelection="true" 
                                            value="#{channelBillController.searchPatient}" 
                                            completeMethod="#{patientController.completePatient}" 
                                            var="apt" itemLabel="#{apt.person.name}" 
                                            itemValue="#{apt}" size="30"  style="width: 400px;">
                                <p:ajax event="itemSelect" process="@this" update="panSearch"/>
                            </p:autoComplete>   

                            <h:panelGrid id="panSearch" columns="2" >
                                <h:outputLabel  rendered="#{channelBillController.searchPatient!=null}" value="Name" />
                                <h:outputLabel rendered="#{channelBillController.searchPatient!=null}" value="#{channelBillController.searchPatient.person.nameWithTitle}" ></h:outputLabel>
                                <h:outputLabel  rendered="#{channelBillController.searchPatient!=null}" value="Phone" />
                                <h:outputLabel rendered="#{channelBillController.searchPatient!=null}" value="#{channelBillController.searchPatient.person.phone}" ></h:outputLabel>
                                <h:outputLabel  rendered="#{channelBillController.searchPatient!=null}" value="Sex" />
                                <h:outputLabel rendered="#{channelBillController.searchPatient!=null}" value="#{channelBillController.searchPatient.person.sex}" ></h:outputLabel>
                            </h:panelGrid>   
                        </p:tab>
                    </p:tabView>
                    <h:panelGrid columns="2" style="min-width: 100%;">


                        <p:commandButton   value="Add" process="@form" 
                                           update="gpThisBookingDetails" style="float: right;" 
                                          action="#{channelBillController.addOnCall()}" 
                                           oncomplete="PF('dlgAdd').show();">                        
                        </p:commandButton>

                        <p:commandButton ajax="false" action="#{channelBillController.makeNull}"  value="New Booking" onclick="onSubmitButton();"/>
                    </h:panelGrid>

                    <p:dialog id="dialogChannelAdded" header="Booked" widgetVar="dlgAdd" 
                              modal="true" height="400" width="600">
                        <p:commandButton value="New Bill" action="#{channelBillController.makeNull()}" ajax="false"
                                         ></p:commandButton>

                        <p:commandButton value="Print" ajax="false" action="#"
                                         disabled="#{channelBillController.billSession.billItem.bill.balance eq 0.0}">
                            <p:printer target="panelAddedBillPrint" ></p:printer>
                        </p:commandButton>


                        <h:panelGroup id="panelAddedBillPrint" styleClass="noBorder" >
                            <div >
                                <h:panelGroup rendered="#{!sessionController.loggedPreference.pharmacyBillPrabodha}" > 
                                    <ch:channelRecipt bill="#{channelBillController.printingBill}" dup="false"/>
                                    <ch:channelRecipt bill="#{channelBillController.printingBill}" dup="false"/>
                                </h:panelGroup>
                            </div>
                            <div >
                                <h:panelGroup rendered="#{sessionController.loggedPreference.pharmacyBillPrabodha}" > 
                                    <ch:channelReciptPos bill="#{channelBillController.printingBill}" dup="false"/>
                                </h:panelGroup>
                            </div>
                        </h:panelGroup>

                    </p:dialog>  

                </p:panel>

                <p:panel id="panelSelectedBookinDetails" rendered="false">
                    <p:tabView id="detail">
                        <p:tab title="Booking" id="booking">
                            <h:panelGrid columns="2">
                                <p:outputLabel value="Patient Name"/>
                                <p:outputLabel value="#{bookingController.selectedBillSession.bill.patient.person.nameWithTitle}"/>
                                <p:outputLabel value="Booking Id"/>
                                <p:outputLabel value="#{bookingController.selectedBillSession.bill.bookingId}"/>
                                <p:outputLabel value="Serial No"/>
                                <ui:repeat value="#{bookingController.selectedBillSession.bill.billItems}" var="bis" >
                                    <p:outputLabel value="#{bis.billSession.serialNo}"/>
                                </ui:repeat>
                                <p:outputLabel value="Payment Method"/>
                                <p:outputLabel value="#{bookingController.selectedBillSession.bill.paymentMethod}"/>
                                <p:outputLabel value="Agent" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                <p:outputLabel value="#{bookingController.selectedBillSession.bill.fromInstitution.name}" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                <p:outputLabel value="Agent Ref No" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                <p:outputLabel value="#{bookingController.selectedBillSession.billItem.agentRefNo}" rendered="#{bookingController.selectedBillSession.bill.paymentMethod eq 'Agent'}"/>
                                <p:outputLabel value="Booking User"/>
                                <p:outputLabel value="#{bookingController.selectedBillSession.bill.creater.webUserPerson.nameWithTitle}"/>
                                <p:outputLabel value="Booked At"/>
                                <p:outputLabel value="#{bookingController.selectedBillSession.bill.createdAt}"> 
                                    <f:convertDateTime pattern="dd MMM yyyy - hh:mm a" ></f:convertDateTime>
                                </p:outputLabel>
                                <p:outputLabel value="Consultant"/>
                                <p:outputLabel value="#{bookingController.selectedBillSession.serviceSession.staff.person.nameWithTitle}"/>
                                <p:outputLabel value="Appointment Date">
                                </p:outputLabel>
                                <p:outputLabel value="#{bookingController.selectedBillSession.sessionDate}"> 
                                    <f:convertDateTime pattern="dd MMM yyyy - hh:mm a" >
                                    </f:convertDateTime>
                                </p:outputLabel>
                                <p:outputLabel value="Appointment Time">
                                </p:outputLabel>
                                <p:outputLabel value="#{bookingController.selectedBillSession.serviceSession.sessionTime}"> 
                                    <f:convertDateTime pattern="hh:mm a" ></f:convertDateTime>
                                </p:outputLabel>
                            </h:panelGrid>                            
                        </p:tab>


                        <p:tab title="Reprint" id="rePrint">

                            <p:commandButton value="Print" ajax="false" action="#">
                                <p:printer target="panelAddedBillPrintRe" ></p:printer>
                            </p:commandButton>


                            <h:panelGroup id="panelAddedBillPrintRe" styleClass="noBorder" >
                                <div >
                                    <h:panelGroup rendered="#{!sessionController.loggedPreference.pharmacyBillPrabodha eq false}" > 
                                        <ch:channelRecipt bill="#{channelBillController.billSession.billItem.bill}" dup="false"/>
                                    </h:panelGroup>
                                </div>
                                <div >
                                    <h:panelGroup rendered="#{sessionController.loggedPreference.pharmacyBillPrabodha eq true}" > 
                                        <ch:channelReciptPos bill="#{channelBillController.billSession.billItem.bill}" dup="false"/>
                                    </h:panelGroup>
                                </div>
                            </h:panelGroup>

                        </p:tab>

                        <p:panel id="panelBillPrint" >

                            <h:panelGroup id="panelAddedBillPrint" styleClass="noBorder">
                                <ch:bill_fees bill="#{channelBillController.billSession.billItem.bill}"/>
                            </h:panelGroup>

                        </p:panel>

                        <p:tab title="Cancel" id="cancel">                                                         

                            <h:panelGroup>
                                <ch:bill_fees bill="#{channelBillController.billSession.billItem.bill}" />
                            </h:panelGroup>
                            <p:commandButton ajax="false" value="Cancel" 
                                             rendered="#{channelBillController.billSession.bill.billType.parent eq 'ChannelCashFlow'}"
                                            action="#{channelBillController.cancelCashFlowBill}"
                                             disabled="#{channelBillController.billSession.bill.refunded==true
                                                         or channelBillController.billSession.bill.cancelled==true}" 
                                             onclick="onSubmitButton();"/>
                            <p:commandButton ajax="false" value="Cancel" 
                                             rendered="#{channelBillController.billSession.bill.billType.parent eq 'ChannelCreditFlow'}"
                                            action="#{channelBillController.cancelCreditPaidBill}"
                                             disabled="#{channelBillController.billSession.bill.refunded==true
                                                         or channelBillController.billSession.bill.cancelled==true}" 
                                             onclick="onSubmitButton();"/>
                        </p:tab>


                        <p:tab title="Refund" id="refund">                          
                            <h:panelGroup>
                                <h:panelGrid columns="2">
                                    <h:outputLabel value="Refundable Total : "/>
                                    <h:outputLabel id="tot" value="#{channelBillController.refundableTotal}"/>
                                </h:panelGrid>
                                <p:dataTable value="#{channelBillController.billSession.bill.billFees}" var="bi">
                                    <p:column headerText="Fee Name">
                                        <p:outputLabel value="#{bi.fee.name}"/>
                                    </p:column>
                                    <p:column headerText="Fee Type">
                                        <p:outputLabel value="#{bi.fee.feeType}"/>
                                    </p:column>
                                    <p:column headerText="Fee Value">
                                        <p:outputLabel value="#{bi.feeValue}"/> 
                                    </p:column>
                                    <p:column headerText="Return Value">
                                        <p:inputText value="#{bi.tmpChangedValue}">
                                            <f:ajax execute="@this" render=":#{p:component('tot')}" event="blur" listener="#{channelBillController.calRefundTotal()}"/>
                                        </p:inputText>

                                    </p:column>
                                </p:dataTable>
                            </h:panelGroup>
                            <p:commandButton ajax="false" value="Refund" 
                                             rendered="#{channelBillController.billSession.bill.billType.parent eq 'ChannelCashFlow'}"
                                            action="#{channelBillController.refundCashFlowBill}" 
                                             disabled="#{channelBillController.billSession.bill.refunded==true
                                                         or channelBillController.billSession.bill.cancelled==true}"
                                             onclick="onSubmitButton();"/>

                            <p:commandButton ajax="false" value="Refund" 
                                             rendered="#{channelBillController.billSession.bill.billType.parent eq 'ChannelCreditFlow'}"
                                            action="#{channelBillController.refundCreditPaidBill}" 
                                             disabled="#{channelBillController.billSession.bill.refunded==true
                                                         or channelBillController.billSession.bill.cancelled==true}"
                                             onclick="onSubmitButton();"/>


                        </p:tab>


                        <p:tab title="Settle" id="settle">
                            <p:panel  id="set">
                                <ch:bill_fees bill="#{channelBillController.billSession.billItem.bill}" />

                                <p:outputLabel value="Payment Method"/>
                                <p:selectOneMenu  id="cmbSettlePs" value="#{channelBillController.settlePaymentMethod}">  
                                    <f:selectItems value="#{enumController.paymentMethodsForChannelSettle}"/>                                                               
                                    <f:ajax execute="@this" render="settleAgent settleAgent2 settleBallance settleBallance2 settleAgRefLbl settleAgRefTxt" event="change" />
                                </p:selectOneMenu>

                                <h:outputLabel id="settleAgent" value="Agent"  style="display: #{channelBillController.settlePaymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                <p:autoComplete id="settleAgent2" forceSelection="true" style="display: #{channelBillController.settlePaymentMethod eq 'Agent'? 'block' : 'none'} ; "
                                                value="#{channelBillController.settleInstitution}"  completeMethod="#{agencyController.completeAgency}" var="ix"
                                                itemLabel="#{ix.name}" itemValue="#{ix}" >
                                    <f:ajax  event="itemSelect" execute="@this"  render="settleBallance settleBallance2 settleAgRefLbl settleAgRefTxt"/>
                                    <p:column>#{ix.institutionCode}</p:column>
                                    <p:column>#{ix.name}</p:column>                                
                                </p:autoComplete> 

                                <h:outputLabel id="settleAgRefLbl" value="Agent Reference No"  style="display: #{channelBillController.settlePaymentMethod eq 'Agent'? 'block' : 'none'} ; "/>
                                <p:inputText autocomplete="off" id="settleAgRefTxt" value="#{channelBillController.settleAgentRefNo}"  style="display: #{channelBillController.settlePaymentMethod eq 'Agent' ? 'block' : 'none'} ; " />

                                <h:outputLabel id="settleBallance" value="Ballance"  style="display: #{channelBillController.paymentMethod eq 'Agent' ? 'block' : 'none'} ; " />
                                <h:outputLabel id="settleBallance2" value="#{channelBillController.institution.ballance}"  style="display: #{channelBillController.settlePaymentMethod eq 'Agent' ? 'block' : 'none'} ; " />


                                <p:commandButton id="setBtn"  value="Settle Credit"
                                                 process="cmbSettlePs settleAgent2 settleAgRefTxt setBtn"
                                                 update="gpSettlePrint"
                                                action="#{channelBillController.settleCredit}" 
                                                 disabled="#{channelBillController.billSession.bill.billType.parent ne 'ChannelCreditFlow' 
                                                             or channelBillController.billSession.bill.cancelled==true
                                                             or  channelBillController.billSession.bill.paidAmount ne 0}" 
                                                 oncomplete="PF('dlgSettle').show();"/>



                                <h:panelGroup id="gpSettlePrint" >


                                    <p:dialog id="test" widgetVar="test" >
                                        <p:commandButton value="New Bill" action="#{channelBillController.makeNull()}" ajax="false" ></p:commandButton>

                                    </p:dialog>

                                    <p:dialog id="dialogChannelSettle" header="Booked" widgetVar="dlgSettle" 
                                              modal="true" height="400" width="600">
                                        <p:commandButton value="New Bill" action="#{channelBillController.makeNull()}" ajax="false" ></p:commandButton>

                                        <p:commandButton value="Print" ajax="false" action="#" disabled="#{channelBillController.billSession.billItem.bill.balance ne 0.0}">
                                            <p:printer target="panelAddedBillPrintSettle" ></p:printer>
                                        </p:commandButton>
                                        <h:panelGroup id="panelAddedBillPrintSettle" styleClass="noBorder" >
                                            <div >
                                                <h:panelGroup rendered="#{sessionController.loggedPreference.pharmacyBillPrabodha eq false}" > 
                                                    <div style="page-break-after: always;">
                                                        <ch:channelRecipt bill="#{channelBillController.billSession.billItem.bill}" dup="false"/>
                                                    </div>
                                                    <div style="page-break-after: always;">
                                                        <ch:channelRecipt bill="#{channelBillController.billSession.billItem.bill}" dup="false"/>
                                                    </div>
                                                </h:panelGroup>
                                            </div>
                                            <div >
                                                <h:panelGroup rendered="#{sessionController.loggedPreference.pharmacyBillPrabodha eq true}" > 
                                                    <ch:channelReciptPos bill="#{channelBillController.billSession.billItem.bill}" dup="false"/>
                                                </h:panelGroup>
                                            </div>
                                        </h:panelGroup>
                                    </p:dialog>
                                </h:panelGroup>

                            </p:panel>

                        </p:tab>


                        <p:tab title="Change" id="change">
                            <h:panelGrid columns="2">
                                <h:outputLabel value="Title"/>
                                <p:selectOneMenu  value="#{bookingController.selectedBillSession.bill.patient.person.title}"  >
                                    <f:selectItems value="#{billController.title}"/>
                                </p:selectOneMenu>
                                <p:outputLabel value="Name"/>
                                <p:inputText autocomplete="off" value="#{bookingController.selectedBillSession.bill.patient.person.name}" />
                                <p:outputLabel value="Patient"/>
                                <p:inputText autocomplete="off" value="#{bookingController.selectedBillSession.bill.patient.person.phone}"/>
                                <p:outputLabel value="Serial No"/>
                                <ui:repeat value="#{bookingController.selectedBillSession.bill.billItems}" var="bis" >
                                    <p:inputText autocomplete="off" value="#{bis.billSession.serialNo}">                                        
                                    </p:inputText>
                                </ui:repeat>
                                <p:outputLabel value="Mark As Absent"/>
                                <p:selectBooleanCheckbox value="#{bookingController.selectedBillSession.absent}" >
                                </p:selectBooleanCheckbox>

                                <p:commandButton ajax="false" value="Update Serial" action="#{bookingController.updateSerial()}"
                                                 disabled="#{bookingController.selectedBillSession.bill.cancelled==true
                                                             or bookingController.selectedBillSession.bill.refunded==true}" onclick="onSubmitButton();"/>
                                <p:commandButton ajax="false" value="Update Patient" action="#{bookingController.updatePatient}"
                                                 disabled="#{bookingController.selectedBillSession.bill.cancelled==true
                                                             or bookingController.selectedBillSession.bill.refunded==true}" onclick="onSubmitButton();"/>

                            </h:panelGrid>



                        </p:tab>


                        <p:tab title="Search">
                            <p:calendar id="cal"  value="#{channelSearchController.date}" pattern="dd MMMM yyyy" >   
                                <f:ajax event="dateSelect" execute="@this" render="bSessionSearch"/>
                            </p:calendar>
                            <p:dataTable id="bSessionSearch" value="#{channelSearchController.billSessions}" var='bs'
                                         filteredValue="#{channelSearchController.filteredbillSessions}">


                                <p:column headerText="Booking Id" filterBy="#{bs.bill.bookingId}" filterMatchMode="contains">
                                    <h:commandLink action="channel_booking" actionListener="#{bookingController.makeNull}"> #{bs.bill.bookingId}
                                        <f:setPropertyActionListener target="#{bookingController.speciality}" value="#{bs.serviceSession.staff.speciality}"/>
                                        <f:setPropertyActionListener target="#{bookingController.staff}" value="#{bs.serviceSession.staff}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession}" value="#{bs.serviceSession}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedBillSession}" value="#{bs}"/>
                                    </h:commandLink>
                                </p:column>
                                <p:column headerText="Sepeciality" filterBy="#{bs.serviceSession.staff.speciality.name}" filterMatchMode="contains">
                                    <h:commandLink action="channel_booking" actionListener="#{bookingController.makeNull}">#{bs.serviceSession.staff.speciality.name}
                                        <f:setPropertyActionListener target="#{bookingController.speciality}" value="#{bs.serviceSession.staff.speciality}"/>
                                        <f:setPropertyActionListener target="#{bookingController.staff}" value="#{bs.serviceSession.staff}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession}" value="#{bs.serviceSession}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedBillSession}" value="#{bs}"/>
                                    </h:commandLink>
                                </p:column>
                                <p:column headerText="Consultant" filterBy="#{bs.serviceSession.staff.person.nameWithTitle}" filterMatchMode="contains">

                                    <h:commandLink action="channel_booking" actionListener="#{bookingController.makeNull}">  #{bs.serviceSession.staff.person.nameWithTitle}
                                        <f:setPropertyActionListener target="#{bookingController.speciality}" value="#{bs.serviceSession.staff.speciality}"/>
                                        <f:setPropertyActionListener target="#{bookingController.staff}" value="#{bs.serviceSession.staff}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession}" value="#{bs.serviceSession}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedBillSession}" value="#{bs}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession.sessionAt}" value="#{bs.sessionDate}"/>
                                    </h:commandLink>
                                </p:column>
                                <p:column headerText="Session Name" filterBy="#{bs.serviceSession.name}" filterMatchMode="contains">
                                    <h:commandLink action="channel_booking" actionListener="#{bookingController.makeNull}">  #{bs.serviceSession.name}
                                        <f:setPropertyActionListener target="#{bookingController.speciality}" value="#{bs.serviceSession.staff.speciality}"/>
                                        <f:setPropertyActionListener target="#{bookingController.staff}" value="#{bs.serviceSession.staff}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession}" value="#{bs.serviceSession}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedBillSession}" value="#{bs}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession.sessionAt}" value="#{bs.sessionDate}"/>
                                    </h:commandLink>
                                </p:column>
                                <p:column headerText="No" filterBy="#{bs.serialNo}" filterMatchMode="contains">
                                    <h:commandLink action="channel_booking" actionListener="#{bookingController.makeNull}"> #{bs.serialNo}
                                        <f:setPropertyActionListener target="#{bookingController.speciality}" value="#{bs.serviceSession.staff.speciality}"/>
                                        <f:setPropertyActionListener target="#{bookingController.staff}" value="#{bs.serviceSession.staff}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedBillSession}"  value="#{bs}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession}" value="#{bs.serviceSession}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession.sessionAt}" value="#{bs.sessionDate}"/>
                                    </h:commandLink>
                                </p:column>
                                <p:column headerText="Patient Name" filterBy="#{bs.bill.patient.person.nameWithTitle}" filterMatchMode="contains">
                                    <h:commandLink action="channel_booking" actionListener="#{bookingController.makeNull}"> #{bs.bill.patient.person.nameWithTitle}
                                        <f:setPropertyActionListener target="#{bookingController.speciality}" value="#{bs.serviceSession.staff.speciality}"/>
                                        <f:setPropertyActionListener target="#{bookingController.staff}" value="#{bs.serviceSession.staff}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession}" value="#{bs.serviceSession}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedBillSession}" value="#{bs}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession.sessionAt}" value="#{bs.sessionDate}"/>
                                    </h:commandLink>
                                </p:column>
                                <p:column headerText="Paid or Not" filterBy="#{bs.bill.billType}" filterMatchMode="contains">
                                    <h:commandLink action="channel_booking" actionListener="#{bookingController.makeNull}"> <p:outputLabel rendered="#{bs.bill.billType eq 'ChannelCredit'}" value="Credit" style="color: red;"/>
                                        <f:setPropertyActionListener target="#{bookingController.speciality}" value="#{bs.serviceSession.staff.speciality}"/>
                                        <f:setPropertyActionListener target="#{bookingController.staff}" value="#{bs.serviceSession.staff}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession}" value="#{bs.serviceSession}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedBillSession}" value="#{bs}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession.sessionAt}" value="#{bs.sessionDate}"/>
                                    </h:commandLink>
                                    <h:commandLink action="channel_booking" actionListener="#{bookingController.makeNull}"> <p:outputLabel rendered="#{bs.bill.billType eq 'ChannelPaid'}" value="Paid"/>
                                        <f:setPropertyActionListener target="#{bookingController.speciality}" value="#{bs.serviceSession.staff.speciality}"/>
                                        <f:setPropertyActionListener target="#{bookingController.staff}" value="#{bs.serviceSession.staff}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession}" value="#{bs.serviceSession}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedBillSession}" value="#{bs}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession.sessionAt}" value="#{bs.sessionDate}"/>
                                    </h:commandLink>
                                </p:column>
                                <p:column headerText="C/R" filterBy="#{bs.bill.billClass}" filterMatchMode="contains">
                                    <h:commandLink action="channel_booking" actionListener="#{bookingController.makeNull}">  <p:outputLabel value="Cancelled" rendered="#{bs.bill.cancelled==true}"/>
                                        <f:setPropertyActionListener target="#{bookingController.speciality}" value="#{bs.serviceSession.staff.speciality}"/>
                                        <f:setPropertyActionListener target="#{bookingController.staff}" value="#{bs.serviceSession.staff}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession}" value="#{bs.serviceSession}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedBillSession}" value="#{bs}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession.sessionAt}" value="#{bs.sessionDate}"/>
                                    </h:commandLink>
                                    <h:commandLink action="channel_booking" actionListener="#{bookingController.makeNull}">  <p:outputLabel value="Refunded" rendered="#{bs.bill.refunded==true}"/>
                                        <f:setPropertyActionListener target="#{bookingController.speciality}" value="#{bs.serviceSession.staff.speciality}"/>
                                        <f:setPropertyActionListener target="#{bookingController.staff}" value="#{bs.serviceSession.staff}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession}" value="#{bs.serviceSession}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedBillSession}" value="#{bs}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession.sessionAt}" value="#{bs.sessionDate}"/>
                                    </h:commandLink>
                                </p:column>   
                                <p:column headerText="Agent" filterBy="#{bs.bill.fromInstitution.institutionCode}" filterMatchMode="contains">
                                    <h:commandLink action="channel_booking" actionListener="#{bookingController.makeNull}"> <p:outputLabel value="#{bs.bill.fromInstitution.institutionCode}"/>      
                                        <f:setPropertyActionListener target="#{bookingController.speciality}" value="#{bs.serviceSession.staff.speciality}"/>
                                        <f:setPropertyActionListener target="#{bookingController.staff}" value="#{bs.serviceSession.staff}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession}" value="#{bs.serviceSession}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedBillSession}" value="#{bs}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession.sessionAt}" value="#{bs.sessionDate}"/>
                                    </h:commandLink>
                                </p:column> 
                                <p:column headerText="Agent Ref No" filterBy="#{bs.billItem.agentRefNo}" filterMatchMode="contains">
                                    <h:commandLink action="channel_booking" actionListener="#{bookingController.makeNull}"><p:outputLabel value="#{bs.billItem.agentRefNo}"/>     
                                        <f:setPropertyActionListener target="#{bookingController.speciality}" value="#{bs.serviceSession.staff.speciality}"/>
                                        <f:setPropertyActionListener target="#{bookingController.staff}" value="#{bs.serviceSession.staff}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession}" value="#{bs.serviceSession}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedBillSession}" value="#{bs}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession.sessionAt}" value="#{bs.sessionDate}"/>
                                    </h:commandLink>
                                </p:column> 
                                <p:column headerText="P/A" filterBy="#{bs.absent}" filterMatchMode="contains">                                      
                                    <h:commandLink action="channel_booking" actionListener="#{bookingController.makeNull}"> <p:outputLabel value="Absent"  rendered="#{bs.absent}"/>  
                                        <f:setPropertyActionListener target="#{bookingController.speciality}" value="#{bs.serviceSession.staff.speciality}"/>
                                        <f:setPropertyActionListener target="#{bookingController.staff}" value="#{bs.serviceSession.staff}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession}" value="#{bs.serviceSession}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedBillSession}" value="#{bs}"/>
                                        <f:setPropertyActionListener target="#{bookingController.selectedServiceSession.sessionAt}" value="#{bs.sessionDate}"/>
                                    </h:commandLink>
                                </p:column> 
                            </p:dataTable> 
                        </p:tab>


                        <p:tab title="Views">
                            <h:panelGrid columns="2">
                                <p:panel header="Selected Session">
                                    <h:panelGrid columns="1">
                                        <p:commandButton value="Nurse View " action="#{bookingController.nurse}"  onclick="onSubmitButton();" >                                       
                                        </p:commandButton>
                                        <p:commandButton value="Doctor View " action="#{bookingController.doctor}" ajax="false" onclick="onSubmitButton();">                                        
                                        </p:commandButton>
                                        <p:commandButton value="Session View " action="#{bookingController.session}" ajax="false" onclick="onSubmitButton();">                                        
                                        </p:commandButton>
                                        <p:commandButton value="Phone View " action="#{bookingController.phone}" ajax="false" onclick="onSubmitButton();">                                        
                                        </p:commandButton>
                                        <p:commandButton value="User View " action="#{bookingController.user}" ajax="false" onclick="onSubmitButton();">                                        
                                        </p:commandButton>
                                    </h:panelGrid>

                                </p:panel>
                                <p:panel header="Today's">
                                    <h:panelGrid columns="1">
                                        <p:commandButton value="All Patient" action="channel_patient_view_today" ajax="false" onclick="onSubmitButton();">                                        
                                        </p:commandButton>
                                        <p:commandButton value="All Doctor" action="channel_doctor_view_today" ajax="false" onclick="onSubmitButton();">                                        
                                        </p:commandButton>
                                    </h:panelGrid>                                    
                                </p:panel>
                            </h:panelGrid>

                        </p:tab>
                    </p:tabView>
                </p:panel>


            </h:panelGrid>

        </h:form>
    </h:body>
</html>
